﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using Internet_Cafe.App_Code;

namespace Internet_Cafe
{
    /// <summary>
    /// Interaction logic for ActivatePC.xaml
    /// </summary>
    public partial class Postpaid : Window
    {
        ComputerItem c;
        public Postpaid(ComputerItem _c)
        {
            c = _c;
            InitializeComponent();
        }

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            if (txtInput.Text.Length < 1)
            {
                MessageBox.Show("Внесете број во полето", "Грешка", MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }
            if (radioHours.IsChecked == true)
            {
                DateTime dt = DateTime.Now;
                dt = dt.AddMinutes(double.Parse(txtInput.Text));
                c.setActivePrepaid(dt);
            }
            else
            {
                DateTime dt = DateTime.Now;
                double vreme = AppHelper.GetTimeFromCost(double.Parse(txtInput.Text));
                dt = dt.AddMinutes(vreme);
                c.setActivePrepaid(dt);
            }
            Close();
        }

        private void txtInput_KeyDown(object sender, KeyEventArgs e)    //KeyEventArgs
        {
            if (!(Char.IsDigit((new KeyConverter().ConvertToString(e.Key)), 0)
                || e.Key == Key.Delete || e.Key == Key.Back))
                e.Handled = true;
        }

        private void RadioButton_Click(object sender, RoutedEventArgs e)
        {
            if (radioHours.IsChecked == true)
            {
                txtLabel.Text = "Mинути:";
            }
            else
            {
                txtLabel.Text = "Пари:";
            }
        }
    }
}
